//
//  StarView.m
//  Food
//
//  Created by dlios on 15/7/16.
//  Copyright (c) 2015年 李志远. All rights reserved.
//

#import "StarView.h"

@implementation StarView


- (void)dealloc
{
    [super dealloc];
    [_view1 release];
    [_view2 release];
    [_view3 release];
    [_view4 release];
    [_view5 release];
    
}


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
      
        self.view1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width/5, self.frame.size.height)];
        [self addSubview:_view1];
        self.view2 = [[UIImageView alloc] initWithFrame:CGRectMake(_view1.frame.size.width, 0, self.frame.size.width/5, self.frame.size.height)];
        [self addSubview:_view2];
        self.view3 = [[UIImageView alloc] initWithFrame:CGRectMake(_view1.frame.size.width*2, 0, self.frame.size.width/5, self.frame.size.height)];
        [self addSubview:_view3];
        self.view4 = [[UIImageView alloc] initWithFrame:CGRectMake(_view1.frame.size.width*3, 0, self.frame.size.width/5, self.frame.size.height)];
        [self addSubview:_view4];
        self.view5 = [[UIImageView alloc] initWithFrame:CGRectMake(_view1.frame.size.width*4, 0, self.frame.size.width/5, self.frame.size.height)];
        [self addSubview:_view5];

        
    }
    
    return self;
}

- (void)createViewWithScore:(CGFloat)score
{
    if (score == 0) {
        _view1.image = [UIImage imageNamed:@"@2x_empty"];
        _view2.image = [UIImage imageNamed:@"@2x_empty"];
        _view3.image = [UIImage imageNamed:@"@2x_empty"];
        _view4.image = [UIImage imageNamed:@"@2x_empty"];
        _view5.image = [UIImage imageNamed:@"@2x_empty"];
    }if (score == 0.5) {
        _view1.image = [UIImage imageNamed:@"@2x_half"];
        _view2.image = [UIImage imageNamed:@"@2x_empty"];
        _view3.image = [UIImage imageNamed:@"@2x_empty"];
        _view4.image = [UIImage imageNamed:@"@2x_empty"];
        _view5.image = [UIImage imageNamed:@"@2x_empty"];

    }if (score == 1) {
        _view1.image = [UIImage imageNamed:@"@2x_full"];
        _view2.image = [UIImage imageNamed:@"@2x_empty"];
        _view3.image = [UIImage imageNamed:@"@2x_empty"];
        _view4.image = [UIImage imageNamed:@"@2x_empty"];
        _view5.image = [UIImage imageNamed:@"@2x_empty"];
    }if (score == 1.5) {
        _view1.image = [UIImage imageNamed:@"@2x_full"];
        _view2.image = [UIImage imageNamed:@"@2x_half"];
        _view3.image = [UIImage imageNamed:@"@2x_empty"];
        _view4.image = [UIImage imageNamed:@"@2x_empty"];
        _view5.image = [UIImage imageNamed:@"@2x_empty"];
    }if (score == 2) {
        _view1.image = [UIImage imageNamed:@"@2x_full"];
        _view2.image = [UIImage imageNamed:@"@2x_full"];
        _view3.image = [UIImage imageNamed:@"@2x_empty"];
        _view4.image = [UIImage imageNamed:@"@2x_empty"];
        _view5.image = [UIImage imageNamed:@"@2x_empty"];

    }if (score == 2.5) {
        _view1.image = [UIImage imageNamed:@"@2x_full"];
        _view2.image = [UIImage imageNamed:@"@2x_full"];
        _view3.image = [UIImage imageNamed:@"@2x_half"];
        _view4.image = [UIImage imageNamed:@"@2x_empty"];
        _view5.image = [UIImage imageNamed:@"@2x_empty"];
    }if (score == 3) {
        _view1.image = [UIImage imageNamed:@"@2x_full"];
        _view2.image = [UIImage imageNamed:@"@2x_full"];
        _view3.image = [UIImage imageNamed:@"@2x_full"];
        _view4.image = [UIImage imageNamed:@"@2x_empty"];
        _view5.image = [UIImage imageNamed:@"@2x_empty"];

    }if (score == 3.5) {
        _view1.image = [UIImage imageNamed:@"@2x_full"];
        _view2.image = [UIImage imageNamed:@"@2x_full"];
        _view3.image = [UIImage imageNamed:@"@2x_full"];
        _view4.image = [UIImage imageNamed:@"@2x_half"];
        _view5.image = [UIImage imageNamed:@"@2x_empty"];

    }if (score == 4) {
        _view1.image = [UIImage imageNamed:@"@2x_full"];
        _view2.image = [UIImage imageNamed:@"@2x_full"];
        _view3.image = [UIImage imageNamed:@"@2x_full"];
        _view4.image = [UIImage imageNamed:@"@2x_full"];
        _view5.image = [UIImage imageNamed:@"@2x_empty"];
    }if (score == 4.5) {
        _view1.image = [UIImage imageNamed:@"@2x_full"];
        _view2.image = [UIImage imageNamed:@"@2x_full"];
        _view3.image = [UIImage imageNamed:@"@2x_full"];
        _view4.image = [UIImage imageNamed:@"@2x_full"];
        _view5.image = [UIImage imageNamed:@"@2x_half"];
    }if (score == 5) {
        _view1.image = [UIImage imageNamed:@"@2x_full"];
        _view2.image = [UIImage imageNamed:@"@2x_full"];
        _view3.image = [UIImage imageNamed:@"@2x_full"];
        _view4.image = [UIImage imageNamed:@"@2x_full"];
        _view5.image = [UIImage imageNamed:@"@2x_full"];

    }
    
    
    
}







/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
